package com.hdax.dmw.item.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdax.dmw.dtos.item.HotItemDto;
import com.hdax.dmw.item.DmItem;
import com.hdax.dmw.item.mappers.DmItemMapper;
import com.hdax.dmw.item.mapstruct.HotItemDtoMapper;
import com.hdax.dmw.item.service.DmItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DmItemServiceImpl extends ServiceImpl<DmItemMapper, DmItem> implements DmItemService {

    @Autowired
    private HotItemDtoMapper hotItemDtoMapper;

    @Override
    public List<HotItemDto> getHotItems(Long itemType1Id) {
        QueryWrapper<DmItem> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("isBanner",1);
        queryWrapper.eq("isRecommend",1);
        queryWrapper.eq("itemType1Id",itemType1Id);
        queryWrapper.orderByDesc("createdTime");
        queryWrapper.last("limit 5");
        return hotItemDtoMapper.toTargetList(list(queryWrapper));
    }
}
